package com.pearadmin.pro.modules.controller;


import com.pearadmin.pro.common.secure.services.SecureUser;
import com.pearadmin.pro.common.secure.uutoken.SecureUserToken;
import com.pearadmin.pro.modules.sys.domain.SysUser;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RequestMapping("")
@RestController
public class TestController {

    @Resource
    RedisTemplate<String, SecureUserToken> redisTemplate;

    @GetMapping("test")
    public String test(){
        SecureUserToken secureUserToken = new SecureUserToken();
        secureUserToken.setToken("123");
        secureUserToken.setCreateTime(LocalDateTime.now());
        SecureUser secureUser = (SecureUser)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        secureUserToken.setSecureUser(secureUser);
        redisTemplate.opsForValue().set("test",secureUserToken);
        return "ok";
    }

    @GetMapping("test2")
    public String test2(){
        SecureUserToken secureUserToken = new SecureUserToken();
        secureUserToken.setToken("123");
        secureUserToken.setCreateTime(LocalDateTime.now());
        SysUser sysUser=new SysUser();
        sysUser.setNickname("xxx");
        sysUser.setLocked(false);
        redisTemplate.opsForValue().set("test2",secureUserToken);      
        return "ok";
    }
    
    @GetMapping("test3")
    public String test3(){
        redisTemplate.opsForValue().get("test2");
        SecureUserToken test = redisTemplate.opsForValue().get("test");
        return "ok";
    }
}
